#include <iostream>
#include <unistd.h>
#include <thread>
#include "TaskQueue.cc"

using std::cout;
using std::endl;
using std::thread;

class SubTask : public Task
{
public:
    void run(void *argv)
    {
        std::cout << "sleep start..." << std::endl;
        sleep(3);
        std::cout << "sleep end..." << std::endl;
    }
};

void start(TaskQueue *tasks)
{
    while (!tasks->empty())
    {
        tasks->front()->run(nullptr);
    }
}

void test1()
{
    TaskQueue que{3};

    Task *t1 = new SubTask();
    Task *t2 = new SubTask();
    Task *t3 = new SubTask();
    que.push_back(t1);
    que.push_back(t2);
    que.push_back(t2);

    thread th1(start, &que);
    thread th2(start, &que);

    th1.join();
    th2.join();
}

int main(int args, char *argv[])
{
    test1();
    return 0;
}